<template>
  <div class="topic">
    <van-sticky>
      <p class="topic-title">专题</p>
    </van-sticky>
    <van-divider />
    <div class="topic-list">
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
      >
        <div v-for="item in list" :key="item.id">
          <img
            :src="item.scene_pic_url"
            alt=""
            class="topic-img"
            @click="godetail(item.id)"
          />
          <p class="topic-name">{{ item.title }}</p>
          <p class="topic-desc">{{ item.subtitle }}</p>
          <p class="topic-price">{{ item.price_info }}起</p>
        </div>
      </van-list>
    </div>
  </div>
</template>

<script setup>
import { topic } from '@/api/topic/index'
import { ref } from 'vue'
import { useRouter } from 'vue-router'
const list = ref([])
const loading = ref(false)
const finished = ref(false)
const start = ref(0)
const router = useRouter()
const onLoad = () => {
  start.value++
  topic({ page: start.value }).then((res) => {
    list.value.push(...res.data)
    loading.value = false
    if (start.value >= res.total) {
      finished.value = true
    }
  })
}
const godetail = (id) => {
  console.log(id)
  router.push({ name: 'topicDetail', params: { id: id } })
}
</script>

<script>
export default {
  name: 'topicView'
}
</script>

<style lang="scss" scoped>
*{
  margin: 0;
  padding: 0;
  list-style: none;
}
.topic {
  width: 750px;
  background-color: #f8f8f8;
  overflow: hidden;
  text-align: center;
  .topic-title {
    font-size: 36px;
    color: #333333;
    letter-spacing: 0;
    font-weight: 500;
    line-height: 50px;
    height: 50px;
    padding: 17px 0 21px 0;
    background-color: #ffffff;
  }

  .topic-list {
    width: 710px;
    margin: 20px auto 120px;
    background-color: #ffffff;
    overflow: hidden;
    .topic-img {
      width: 710px;
      height: 343px;
    }
    .topic-name {
      font-size: 30px;
      color: #333333;
      letter-spacing: 0;
      font-weight: 500;
      margin-top: 32px;
      line-height: 42px;
      height: 42px;
    }
    .topic-desc {
      font-size: 26px;
      color: #999999;
      letter-spacing: 0;
      font-weight: 400;
      margin-top: 4px;
      height: 37px;
      line-height: 37px;
    }
    .topic-price {
      font-size: 26px;
      color: #9e4242;
      letter-spacing: 0;
      font-weight: 600;
      margin: 16px 0 29px;
      height: 37px;
      line-height: 37px;
    }
  }
}
p {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
</style>
